Public Sub RayTraceable_DrawBackfacesRemoved(ByVal pic As PictureBox)
RayTraceable_DrawWireFrame pic
End Sub
' Return the red, green, and blue components of
' the surface at the hit position.
Public Sub RayTraceable_FindHitColor(ByVal depth As Integer, Objects As Collection, ByVal eye_x As Single, ByVal eye_y As Single, ByVal eye_z As Single, ByVal px As Single, ByVal py As Single, ByVal pz As Single, ByRef R As Integer, ByRef G As Integer, ByRef B As Integer)
Public Sub RayTraceable_CullScanline(ByVal px As Single, ByVal py As Single, ByVal pz As Single, ByVal Nx As Single, ByVal Ny As Single, ByVal Nz As Single)
Dim dx As Single
Dim dy As Single
Dim dz As Single
Dim dist As Single
' See if we will ever be visible again.
If ForeverCulled Then
DoneOnThisScanline = True
Exit Sub
End If
' We have not yet had a hit on this scanline.
HadHit = False
' Find the distance from the center of the
' disk to the scanline plane.
' Get the vector from our center to the point.
With Point1
dx = .Trans(1) - px
dy = .Trans(2) - py
dz = .Trans(3) - pz
End With
' Take the dot product of this and the normal.
' If the resulting distance > Radius, cull.
DoneOnThisScanline = (Abs(dx * Nx + dy * Ny + dz * Nz) > Radius)
' See if we will be culled in the future.
If DoneOnThisScanline Then
' We were not culled on a previous scanline
' but we are now. We will be culled on
' all later scanlines.
If HadHitOnPreviousScanline Then ForeverCulled = True
Else
' We are not culled. Remember that.
HadHitOnPreviousScanline = True
End If
End Sub
' Return the value T for the point of intersection
' between the vector from point (px, py, pz) in
' the direction <vx, vy, vz>.
'
' direct_calculation is true if we are finding the
' intersection from a viewing position ray. It is
' false if we are finding an reflected intersection
' or a shadow feeler.
Public Function RayTraceable_FindT(ByVal direct_calculation As Boolean, ByVal px As Single, ByVal py As Single, ByVal pz As Single, ByVal Vx As Single, ByVal Vy As Single, ByVal Vz As Single) As Single
Dim A As Single
Dim B As Single
Dim C As Single
Dim D As Single
Dim Nx As Single
Dim Ny As Single
Dim Nz As Single
Dim denom As Single
Dim t As Single
Dim Cx As Single
Dim Cy As Single
Dim Cz As Single
Dim dx As Single
Dim dy As Single
Dim dz As Single
Dim X As Single
Dim Y As Single
Dim Z As Single
' See if we have been culled.
If direct_calculation And DoneOnThisScanline Then
RayTraceable_FindT = -1
Exit Function
End If
' Find the unit normal at this point.
GetUnitNormal Nx, Ny, Nz
' Compute the plane's parameters.
A = Nx
B = Ny
C = Nz
D = -(Nx * Point1.Trans(1) + _
Ny * Point1.Trans(2) + _
Nz * Point1.Trans(3))
' If the denominator = 0, the ray is parallel
' to the plane so there's no intersection.
denom = A * Vx + B * Vy + C * Vz
If denom = 0 Then
RayTraceable_FindT = -1
Exit Function
End If
' Solve for t.
t = -(A * px + B * py + C * pz + D) / denom
' If there is no positive t value, there's no
' intersection in this direction.
If t < 0.01 Then
RayTraceable_FindT = -1
Exit Function
End If
' Get the coordinates of the disk's center.
Cx = Point1.Trans(1)
Cy = Point1.Trans(2)
Cz = Point1.Trans(3)
' Get the point of intersection with the plane.
X = px + t * Vx
Y = py + t * Vy
Z = pz + t * Vz
' See if the point is within distance
' Radius of the center.
dx = Cx - X
dy = Cy - Y
dz = Cz - Z
If dx * dx + dy * dy + dz * dz > Radius * Radius Then
' We are not within distance Radius.
RayTraceable_FindT = -1
Exit Function
End If
' We had a hit.
If direct_calculation Then HadHit = True
RayTraceable_FindT = t
End Function
' Return the minimum and maximum distances from
' this point.
' Use the wireframe points.
Private Sub RayTraceable_GetRminRmax(new_min As Single, new_max As Single, ByVal X As Single, ByVal Y As Single, ByVal Z As Single)